﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MLRobotic.Tower.Common
{
    public static class SystemInfo
    {
        private const int SPI_GETPLATFORMTYPE = 257; // PocketPC
        private const int SPI_GETOEMINFO = 258; // HTC_Touch_Pro2_T7385
        private const int SPI_GETPLATFORMNAME = 260; // HTC_Touch_Pro2_T7385  
        private const int SPI_GETPLATFORMMANUFACTURER = 262; // HTC

        [DllImport("coredll.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)]
        private static extern int SystemParametersInfoString(int uiAction, int uiParam, StringBuilder pvParam, int fWinIni);

        public static string GetPlatformType()
        {
            return GetSystemParametersInfo(SPI_GETPLATFORMTYPE);
        }

        public static string GetOemInfo()
        {
            return GetSystemParametersInfo(SPI_GETOEMINFO);
        }

        public static string GetPlatformName()
        {
            return GetSystemParametersInfo(SPI_GETPLATFORMNAME);
        }

        public static string GetPlatformManufacturer()
        {
            return GetSystemParametersInfo(SPI_GETPLATFORMMANUFACTURER);
        }

        public static bool IsTouchPro2()
        {
            return GetPlatformName() == "HTC_Touch_Pro2_T7385";
        }

        private static string GetSystemParametersInfo(int uiAction)
        {
            try
            {
                StringBuilder sb = new StringBuilder(256);

                if (SystemParametersInfoString(uiAction, sb.Capacity, sb, 0) != 0)
                {
                    return sb.ToString().Trim();
                }
            }
            catch
            {
            }

            return "Unknown";
        }
    }
}
